// pages/mine/mypublish/mypublish.js
var app = getApp()
Page({
    /**
     * 页面的初始数据
     */
    data: {
        petList: [],
        page: 1,
        length: 1
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this;
        //调用应用实例的方法获取全局数据
        wx.showLoading({
          title: '加载中',
        });
        that.queryPetList();
    },   
    queryPetList: function(){
        let that = this;
        let data = 'pageNum='+ that.data.page+'&pageSize=10'
        wx.showToast({
          title: '加载中！',
          icon: 'loading',
          duration: 1000
        });
        let fn = res => {
          let _list = that.data.petList;
          for (var i = 0; i < res.data.data.length; i++) {
            _list.push(res.data.data[i]);
          }
          if (that.data.page == 1) {
            _list = res.data.data;
          }
          that.setData({
            petList: _list,
            page: _list.length >= 10 ? 1: Math.floor(_list.length/10)+1,
            length: res.data.data.length
          })
        }
        app.ajax('/petLost/user/list?'+data, 'get', '', fn)
      },
      onPullDownRefresh: function () {
        wx.showNavigationBarLoading() //在标题栏中显示加载
        //模拟加载
        this.queryPetList();
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      },
      //加载更多
      onReachBottom: function() {
        let that = this;
        if (that.data.length < 10) {
          wx.showToast({
            title: '没有更多了',
            icon: 'none'
          })
          return false;
        } else {
          wx.showToast({
            title: '加载中！',
            icon: 'loading',
            duration: 1000
          });
        }
        this.queryPetList();
      },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})